# -*- coding: utf-8 -*-
# @author : wanglei
# @date : 2020/5/11 5:21 PM
# @description : 几何公共方法
from manimlib.imports import *


def get_arc_point(v, w, radius=0.5):
    pass


def get_arc_angle(v, w):
    '''
    获取角度弧线点
    :param v:
    :param w:
    :param radius:
    :return:
    '''
    v_angle, w_angle = v.get_angle(), w.get_angle()
    nudge = 0.05
    start_angle = interpolate(v_angle, w_angle, nudge)
    angle = (1 - 2 * nudge) * (w_angle - v_angle)
    return start_angle, angle


def get_right_angle(pointA, pointB, pointC, size=1):
    '''
    获取直角的直角线
    :param pointA:
    :param pointB: 两直线的直角点
    :param pointC:
    :param size:
    :return:
    '''
    v1 = pointA - pointB
    v1 = size * v1 / get_norm(v1)
    v2 = pointC - pointB
    v2 = size * v2 / get_norm(v2)

    P = pointB # 夹角点
    Q = pointB + v1
    R = Q + v2
    S = R - v1
    # angle_sign = VMobject()
    # angle_sign.set_points_as_corners([P, Q, R, S, P])
    # angle_sign.mark_paths_closed = True
    # angle_sign.set_fill(color=WHITE, opacity=1)
    # angle_sign.set_stroke(width=0)
    # return angle_sign
    return P, Q, R, S


def get_projected_point(v, w):
    '''
    v在w上的投影点坐标
    :param v:
    :param w:
    :return:
    '''
    dot_product = np.dot(v.get_end(), w.get_end())  # 获取两向量的点积值，然后反求投影向量
    return w.get_end() * dot_product / (w.get_length() ** 2)  # 因为是v在w上的投影点坐标，所以应该是w的方向
